package com.example.questionnaire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.questionnaire.dao.QuestionnaireViewMapper;
import com.example.questionnaire.pojo.DO.QuestionnaireView;
import com.example.questionnaire.service.QuestionnaireViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class QuestionnaireViewServiceImpl implements QuestionnaireViewService {

    @Autowired
    private QuestionnaireViewMapper questionnaireViewMapper;


    @Override
    public boolean SetTheAppearanceOfTheQuestionnaire(String formid, boolean toEnableTheCover, String img, String btnText, String backgroundColor, boolean isActivitiesThat, String activitiesBtnBgColor, String graphicPageLinks, boolean customButton, String customButtonColor, String customButtonUrl, String bgImg, String submitBtnColor, String titleColor, String topicDryColor, String textSize, String titleSize) {
        UpdateWrapper<QuestionnaireView> wrapper = new UpdateWrapper<>();
        wrapper.eq("formid", formid)
                .set("to_enable_the_cover",toEnableTheCover)
                .set("img", img)
                .set("btn_text",btnText)
                .set("background_color",backgroundColor)
                .set("is_activities_that",isActivitiesThat)
                .set("activities_btn_bg_color",activitiesBtnBgColor)
                .set("graphic_page_links",graphicPageLinks)
                .set("custom_button",customButton)
                .set("custom_button_color",customButtonColor)
                .set("custom_button_url",customButtonUrl)
                .set("bg_img", bgImg)
                .set("submit_btn_color",submitBtnColor)
                .set("title_color",titleColor)
                .set("topic_dry_color",topicDryColor)
                .set("text_size",textSize)
                .set("title_size",titleSize);
        if(questionnaireViewMapper.update(null, wrapper) < 1){
            throw new RuntimeException("设置失败");
        }
        return true;
    }

    //    @Override
//    public boolean SetTheAppearanceOfTheQuestionnaire(String formid, String toEnableTheCover, String btnText, String backgroundColor, boolean isActivitiesThat, String activitiesBtnBgColor, String graphicPageLinks, boolean customButton, String customButtonColor, String customButtonUrl, String submitBtnColor, String titleColor, String topicDryColor, String textSize, String titleSize) {
//        UpdateWrapper<QuestionnaireView> wrapper = new UpdateWrapper<>();
//        wrapper.eq("formid", formid)
//                .set("to_enable_the_cover",toEnableTheCover)
//                .set("btn_text",btnText)
//                .set("background_color",backgroundColor)
//                .set("is_activities_that",isActivitiesThat)
//                .set("activities_btn_bg_color",activitiesBtnBgColor)
//                .set("graphic_page_links",graphicPageLinks)
//                .set("custom_button",customButton)
//                .set("custom_button_color",customButtonColor)
//                .set("custom_button_url",customButtonUrl)
//                .set("submit_btn_color",submitBtnColor)
//                .set("title_color",titleColor)
//                .set("topic_dry_color",topicDryColor)
//                .set("text_size",textSize)
//                .set("title_size",titleSize);
//        if(questionnaireViewMapper.update(null, wrapper) < 1){
//            throw new RuntimeException("设置失败");
//        }
//        return true;
//    }

    @Override
    public QuestionnaireView getTheAppearanceOfTheQuestionnaire(String formid) {
        QuestionnaireView questionnaireView = questionnaireViewMapper.selectOne(new QueryWrapper<QuestionnaireView>().eq("formid", formid));

     //   System.out.println("啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"+questionnaireView.getId());
        if(questionnaireView != null){
            questionnaireView.setId(null);
            questionnaireView.setCreateTime(null);
            questionnaireView.setModifiedTime(null);
            if(questionnaireView.getBtnText() != null){
                return questionnaireView;
            }
        }


        return null;

    }
}
